import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { hasToken } from 'utils/storage';
function AuthRouter({ component: Comp, ...rest }) {
  //   console.log(5, rest);
  return (
    <Route
      {...rest}
      render={(props) => {
        // console.log('props', props);
        if (hasToken()) {
          return <Comp {...props}></Comp>;
        } else {
          return (
            <Redirect
              to={{ pathname: '/login', state: { from: props.location } }}
            ></Redirect>
          );
        }
      }}
    ></Route>
  );
}

export default AuthRouter;
